Ext.onReady(function(){
	var d = new Date();
	
	var fileAttachment = Ext.create('component.file.attachment',{
        objectId: '',
        imageType: "9",
        contextPath:jypath,
        colspan:2
   });

	var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
	   var fromPanelInfo = Ext.create('Ext.form.FormPanel',{
		   renderTo:Ext.getBody(),
		   frame: true,
	       collapsible: false,
	       autoScroll:false,
			defaults : {
				anchor : '100%'
			},
			
	       title:'面积补差信息',
		   items:[{
				xtype : "container",
				layout : "hbox",
				items : [ {
					   xtype:'displayfield',
			    	   fieldLabel:'房号',
			    	   name:'combinedName'
			    	   
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [{
					 xtype:'displayfield',
			    	 fieldLabel:'合同编号',
			    	 flex:1,
			    	 name:'signCode'
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'客户名称',
			    	 flex:1,
			    	 name:'customerName'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'建筑面积',
			    	 flex:1,
			    	 name:'buildingArea'
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'套内面积',
			    	 name:'roomCombox',
			    	 flex:1,
			    	 name:'innerArea'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [{
					 xtype:'displayfield',
			    	 fieldLabel:'合同单价',
			    	 flex:1,
			    	 name:'signPrice'
				}, {
					 xtype:'displayfield',
			    	 fieldLabel:'合同总价',
			    	 flex:1,
			    	 name:'signAmount'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'计价面积',
			    	 name:'calculateArea'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'numberfield',
			    	 fieldLabel:'实测面积',
			    	 name: "measuredArea",
			    	 hideTrigger:true,
			    	 width:'200',
			    	 minValue:0,
			    	 maxValue:10000,
			    	 decimalPrecision:2,
			    	  listeners: {
		                    change: function(field, value) {
			                     if(value!=null&&value!=""){
			                    	var form = fromPanelInfo.getForm();
			                    	value = parseFloat(value); //实测面积
			                    	var calculateArea= null; //计价面积
			                    	var strCalculateArea = form.findField("calculateArea").getValue();
			                    	if(strCalculateArea==null||strCalculateArea==""){
			                    		calculateArea=parseFloat("0");
			                    	}else{
			                    		calculateArea=parseFloat(strCalculateArea);
			                    	}
			                    	//实测面积-计价面积= 差补面积
			                    	var cmp = value-calculateArea;
			                    	//单价
			                    	var signPrice = form.findField("signPrice").getValue();
			                    	var total = cmp*signPrice; //差补面积总金额
			                    	//总价
			                    	form.findField("makeBalance").setValue(total.toFixed(2));
			                    	
			                     }else{
			                    	 form.findField("makeBalance").setValue("0");
			                     }
		                    }
		                },
		                name:'measuredArea',
		                allowBlank:false,
				    	blankText:'不能为空'
				}]
				
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'补差额',
			    	 name:'makeBalance'
				}]
			},{
				xtype : "container",
				layout : "hbox",
				items : [{
					xtype : 'textarea',
					fieldLabel : '备注',
					width:500,
			    	flex:1,
			    	name:'remark',
			    	maxLength:100
			    	
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [{
					 xtype:'datefield',
			    	 fieldLabel:'应收日期',
			    	 format:'Y-m-d',
		    		allowBlank:false,
			    	blankText:'不能为空',
			    	id:'receivableDate',
			    	name: "receivableDate"
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'datefield',
			    	 fieldLabel:'经办日期',
			    	 format:'Y-m-d',
			    	 allowBlank:false,
				     blankText:'不能为空',
				     id:'trusteesDate',
				     name:'trusteesDate'
				} ]
			},{
				xtype : "container",
				layout : "hbox",
				items : [ {
					 xtype:'displayfield',
			    	 fieldLabel:'操作员',
			    	 flex:1,
			    	 value : userName
				},{
					 xtype:'displayfield',
			    	 fieldLabel:'操作时间',
			    	 flex:1,
			    	 value:str
				} ]
			},fileAttachment],  dockedItems: [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            ui: 'footer',
	            layout: {
	                pack: 'center'
	            },
	            items: [
	            	{
		                xtype: "displayfield",
		                minWidth: 80,
		                id: "auditStatusDesc",
		                name: "auditStatusDesc",
		                value: "审核中...",
		                hidden: true
		            },
	            	{
	                minWidth: 80,
	                text: '提交',
	                id: "submit",
	                name: "submit",
	                hidden:dealReserveAreaAdd,
	                handler:function(){
	                	var form = fromPanelInfo.getForm();
	                	
	                	//验证经办日期，不能超过当前日期
	                	if(Date.parse(Ext.getCmp("trusteesDate").getValue())>Date.parse(new Date())){
	                		 Ext.MessageBox.alert("系统提示","经办日期不能超过当期日期!"); 
	                		 return;
	                	}
	                	
	                	if(form.isValid()){
	                		var fileUrlArr = fileAttachment.getFileArrs();
	                		var parent={
		                			'signedId':sigId,
		                			'measuredArea':form.findField("measuredArea").getValue(),
		                			'makeBalance':form.findField("makeBalance").getValue(),
		                			'start':Ext.getCmp("receivableDate").getValue(),
		                			'end':Ext.getCmp("trusteesDate").getValue(),
		                			'auditStatus':'0',
		                			'remark':form.findField("remark").getValue(),
		                			fileUrlArr:fileUrlArr,
		                			imageType: "9"
		                	};
	                		Ext.Ajax.request({
		                		url:jypath+'/marketing/reserveArea/add',
		                		params:parent,
		                		callback: function (options, success, response) {
		                			 var obj = JSON.parse(response.responseText);
		                			 if(obj.res=="1"){
		    							 Ext.MessageBox.alert("系统提示","保存成功");
		    							 setTimeout(function(){
		    				                	location.href=jypath+"/deal/areaRepair/index?menu="+menu;
			     						}, 2000); 
		    						 }else{
		    							 Ext.MessageBox.alert("系统提示",obj.resMsg); 
		    						 }
		                		}
		                	});
	                	}
	                }
	            },{
	                minWidth: 80,
	                text: '返回',
	                handler:function(){
	                	location.href=jypath+"/deal/areaRepair/index?menu="+menu;
	                }
	            }]
	        }
	        ]
		   
	   });
	   fromPanelInfo.getForm().load({
			url:jypath+'/marketing/reserveArea/loadReserveAreaForm',
			params:{'sigId':sigId},
			success:function(form, action){
				var obj = action.result.data;
				if(obj.trusteesDate!=""&&obj.trusteesDate!=null){
					//alert(trusteesDate);
					Ext.getCmp("trusteesDate").setValue(Ext.Date.format(new Date(obj.trusteesDate),'Y-m-d'));
					Ext.getCmp("receivableDate").setValue(Ext.Date.format(new Date(obj.receivableDate),'Y-m-d'));
				}else{
					Ext.getCmp("trusteesDate").setValue(d);
				}
				var auditStatus = obj.auditStatus;
				//审核中或已通过,不显示提交按钮
				if(auditStatus == "0" || auditStatus == "1"){
					Ext.getCmp("submit").hide();
					/*
					var asd = "";
					Ext.getCmp("auditStatusDesc").show();
					if(auditStatus == 1){
						asd = "<font color='red'>审核中...</font>";
					}else if(auditStatus == 3){
						asd = "<font color='red'>审核已通过...</font>";
					}
					Ext.getCmp("auditStatusDesc").setValue(asd);
					*/
				}
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		}); 
	  
});